﻿using Microsoft.Extensions.DependencyInjection;
using System;
using TianShu.Json;
using TianShu.Modularity;
using TianShu.MultiTenancy;
using TianShu.Serialization;
using TianShu.Threading;
using TianShu.Uow;

namespace TianShu.Caching
{
    [DependsOn(
        typeof(AbpThreadingModule),
        typeof(AbpSerializationModule),
        typeof(AbpUnitOfWorkModule),
        typeof(AbpMultiTenancyModule),
        typeof(AbpJsonModule))]
    public class AbpCachingModule : AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            context.Services.AddMemoryCache();
            context.Services.AddDistributedMemoryCache();

            context.Services.AddSingleton(typeof(IDistributedCache<>), typeof(DistributedCache<>));
            context.Services.AddSingleton(typeof(IDistributedCache<,>), typeof(DistributedCache<,>));

            context.Services.Configure<AbpDistributedCacheOptions>(cacheOptions =>
            {
                cacheOptions.GlobalCacheEntryOptions.SlidingExpiration = TimeSpan.FromMinutes(20);
            });
        }
    }
}
